{
  Messenger Server
  IPC Shared Memory
  Maintainer(s): Timthy O'Neill
}

unit Messenger;

interface

uses
  Windows;

type
  TSharedMemory = record
    IPCMessage : String[255];
  end;
  CSharedMemory = ^TSharedMemory;

var
  SharedMemory : CSharedMemory;

function CreateMap() : Boolean;
function OpenMap() : Boolean;
function ConnectMap() : Boolean;

implementation

var
  MapHandle    : HWND;

const
  MapName : string = '{CB6272CE-ADC1-45F1-91B0-08BF5995E035}';

function CreateMap() : Boolean;
begin
  MapHandle := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0,
                                 SizeOf(TSharedMemory), PChar(MapName));
  Result := ConnectMap();
end;

function OpenMap() : Boolean;
begin
  MapHandle := OpenFileMapping(FILE_MAP_ALL_ACCESS, False, PChar(MapName));
  Result := ConnectMap();
end;

function ConnectMap() : Boolean;
begin
  if MapHandle = 0 then
    Result := False
  else
  begin
    SharedMemory := MapViewOfFile(MapHandle, FILE_MAP_ALL_ACCESS, 0, 0,
                                  SizeOf(TSharedMemory));
    Result := True;
  end;
end;

initialization
begin

end;

end.


